<?php

//echo br(3); ###########################################################################################

	$TEMP->set_file(array('handle' => DIR_VIEW_DEAN . 'semester.html'));
	
	$CID 	= _GET('cid');
	
	$listSemestersDefault = $DSC->getListSemestersDefault();
	$semesterLinker = $DSC->getSemesterLinker($CID, '', false);
	$semActive = array();
	if ( !empty($semesterLinker) ) {
		foreach($semesterLinker as $semesterLinkerValue) {
			$semActive[] = $semesterLinkerValue['sem_idFK'];
		}
	}
	$getChecklistHeader = $DSC->getChecklistHeader($strAccDept);
	$headID	 	= $getChecklistHeader['head_idPK'];

	# LISTING
	if ( !empty($listSemestersDefault) && !empty($CID) ) {
		$TEMP->set_block('handle',  'semester', 'semesterRow');
		$bgcolor 	= LOOPING_F0F;
		foreach($listSemestersDefault as $listSemestersDefaultField => $listSemestersDefaultValue) {
			
			$semID = $listSemestersDefaultValue['sem_idPK'];
			
			//semID, courseID, headID, activeAction
			
			if (!empty($semActive)) {
				
				$semIDFk = 0;
				foreach($semActive as $semActiveValue) {
					if ($semActiveValue == $semID) {
						$semIDFk = $semActiveValue;
					}
				}
				
				if (in_array($semID, $semActive)) {
					
					$getSemesterLinkerNote = $DSC->getSemesterLinkerNote($semIDFk, $CID, $activeYear);
					
					if ( $getSemesterLinkerNote['is_deleted'] == 'Y' ) {
						$edButton = '<img src="' . DIR_IMAGES . 'icon/checkbox_uncheck.png" title="Check" border="0" class="cursor-pointer" onclick="updateActiveSem(\'' . $getSemesterLinkerNote['sem_linker_idPK'] . '\')"/>&nbsp;
								 <img src="' . DIR_IMAGES . 'icon/note_d.png" title="Check" border="0"/>';
						$classDis = 'sem-color-grey icon-button';
					}
					else {
						$edButton = '<img src="' . DIR_IMAGES . 'icon/checkbox_check.png" id="checkbox_check' . $semID . '" title="Check" border="0" class="cursor-pointer" onclick="deleteActiveSem(\'' . $getSemesterLinkerNote['sem_linker_idPK'] . '\')"/>&nbsp; ';
						$edButton .= (!empty($getSemesterLinkerNote['note'])) ? '<img src="' . DIR_IMAGES . 'icon/note.png" id="sem_note_save' . $getSemesterLinkerNote['sem_linker_idPK'] . '" title="Check" border="0" class="cursor-pointer" onclick="semNote(\'' . $semID . '\',   \'' . $getSemesterLinkerNote['sem_linker_idPK'] . '\',   \'' . $getSemesterLinkerNote['note'] . '\')"/>'
																			  : '<img src="' . DIR_IMAGES . 'icon/note_x.png" id="sem_note_save' . $getSemesterLinkerNote['sem_linker_idPK'] . '" title="Check" border="0" class="cursor-pointer" onclick="semNote(\'' . $semID . '\', \'' . $getSemesterLinkerNote['sem_linker_idPK'] . '\',   \'' . $getSemesterLinkerNote['note'] . '\')"/>';
						$classDis = 'icon-button';
					}
					
				}
				else {
					
					$edButton = '<img src="' . DIR_IMAGES . 'icon/checkbox_uncheck.png" title="Check" border="0" class="cursor-pointer" onclick="insertActiveSem(\'' . $semID . '\', \'' . $CID . '\', \'' . $headID . '\', \'' . $activeYear . '\', \'1\')"/>&nbsp;
								 <img src="' . DIR_IMAGES . 'icon/note_d.png" title="Check" border="0"/>';
					$classDis = 'sem-color-grey icon-button';
					
				}
			}
			else {
				$edButton = '<img src="' . DIR_IMAGES . 'icon/checkbox_uncheck.png" title="Check" border="0" class="cursor-pointer" onclick="insertActiveSem(\'' . $semID . '\', \'' . $CID . '\', \'' . $headID . '\', \'' . $activeYear . '\', \'1\')"/>&nbsp;
							 <img src="' . DIR_IMAGES . 'icon/note_d.png" title="Check" border="0"/>';
				$classDis = 'sem-color-grey icon-button';
			}
			
			$semDesc = '<div class="' . $classDis . '">' . $listSemestersDefaultValue['sem_desc'] . ' (' . $listSemestersDefaultValue['sem_code'] . ')</div>';
			
			$TEMP->set_var(array('sem_desc_code' 	=> $semDesc,
								 'sem_id'			=> $semID,
								 'bgcolor'			=> $bgcolor,
								 'ed_button'		=> $edButton));
								 
			$bgcolor = ($bgcolor == LOOPING_F0F) ? LOOPING_FFF : LOOPING_F0F;
			$TEMP->parse('semesterRow', 'semester', true);
		}
	}
	else {
		$TEMP->set_var(array('sem_desc_code' 	=> '',
							 'ed_button'		=> ''));
	}
	
	##################### CHECKLIST HEADER #####################
	
		$courseHeader = $DSC->getCourseHeader($strAccDept);
		$getCourse 	  = $DSC->getCourse($CID);
	
		#SET Course
		if(!empty($getCourse)) {
			$course_label	= $getCourse['course_desc'] . ' (' . $getCourse['course_code'] . ')';
			$course_title	= $course_label;
		}
		else {
			$course_label	= '______________________________________________';
			$course_title	= '&nbsp;';
		}
		
		#SET Checklist Header
		if(!empty($getCourse)) {
			$based 		 	= $courseHeader['head_based'];
			$year 		 	= $courseHeader['head_year'];
		}
		else {
			$based 		 	= '__________________________________';
			$year 		 	= '_______________';
		}
	
	##################### CHECKLIST HEADER #####################
	
	$TEMP->set_var(array('search' 			=> $search,
						 'dean_sub_menu'	=> $pageLib->deanSubMenu(DIR_IMAGES),
						 'dept_course'		=> $strAccCourse,
						 'course_desc'		=> $course_label,
						 'course_title'		=> $course_title,
						 'course_id'		=> $CID,
						 'based'			=> $based,
						 'year'				=> $year
						));
?>